package user_center;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@SpringBootApplication
@MapperScan("user_center.*")
@EnableFeignClients
@EnableResourceServer//Oauth2资源服务器鉴权
@EnableDiscoveryClient
public class UserCenterApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext run = SpringApplication.run(UserCenterApplication.class, args);
//        while(true) {
//            //When configurations are refreshed dynamically, they will be updated in the Enviroment, therefore here we retrieve configurations from Environment every other second.
//            String userName = run.getEnvironment().getProperty("user.name");
//            String userAge = run.getEnvironment().getProperty("user.age");
//            System.err.println("user name :" + userName + "; age: " + userAge);
//            TimeUnit.SECONDS.sleep(1);
//        }
    }

//    //Instantiate RestTemplate Instance
//    @Bean
//    public RestTemplate restTemplate(){
//        return new RestTemplate();
//    }
//
//    @RestController
//    public class NacosController{
//
//        @Autowired
//        private LoadBalancerClient loadBalancerClient;
//        @Autowired
//        private RestTemplate restTemplate;
//
//        @Value("${spring.application.name}")
//        private String appName;
//
//        @GetMapping("/echo/app-name")
//        public String echoAppName(){
//            //Access through the combination of LoadBalanceClient and RestTemplate
//            ServiceInstance serviceInstance = loadBalancerClient.choose("user_center");
//            String path = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName);
//            System.out.println("request path:" +path);
//            return restTemplate.getForObject(path,String.class);
//        }
//
//        @RestController
//        public class EchoController {
//            @GetMapping(value = "/echo/{string}")
//            public String echo(@PathVariable String string) {
//                return "Hello Nacos Discovery " + string;
//            }
//        }
//
//    }

}
